import {
	objDeepCopy,
	getDateString
} from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {

	},
	methods: {
		init() {
			this.getList(this)//140退料
		},

		//获取列表
		getList(that,params,page) {
			params = params || {businessType: 140},
			page = page || this.Model.page;
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/materialsList',
				// url:'/api/supplier/whWarehouse/materialsList',
				data: {
					condition:params,
					pageIndex:page.pageIndex,
					pageSize:page.pageSize
				}
			}).then((res) => {
				var data = res.data;
				that.Model.tableData = [];
				if (data.status == 200) {
					var result = data.result.result;
					var obj;
					var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination);
					if(result){
						for (let i = 0; i < result.length; i++) {
							obj = objDeepCopy(result[i]);
							obj.returnStatus = obj.statusDict.value;//退料单状态
							
							
							that.Model.tableData.push(obj);
						}
					}

				} else {
					that.tips(that, 'warning', data.msg);
				}

			});
		},

		//点击新建
		newPage() {
			this.$router.push({
				path: 'returnListNew',
				query: {
					
				}
			});
		},
		//点击 查看详情
		toDetial(row) {
			this.$router.push({
				path: 'returnListDetail',
				query: {
					id:row.id
				}
			});
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			
		},
		handleCurrentChange(val) {
			var params = this.Model.searchFromData;
			var page = this.Model.page;
			page.pageIndex = val;
			this.getList(this,params,page);
			
		},
		handleSizeChange(val) {
			var params = this.Model.searchFromData;
			var page = this.Model.page;
			page.pageSize = val;
			this.getList(this,params,page);
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			
			var obj;
			obj = {
				keyWord: val.keyWord,
				status: val.status,
				businessType: 140
			}
			if(val.receiptTime){
				obj.gMaterialStartTime = getDateString(val.receiptTime[0]);
				obj.gMaterialEndTime = getDateString(val.receiptTime[1]);
			}
			if(val.orderTime){
				obj.ordersStartTime = getDateString(val.orderTime[0]);
				obj.ordersEndTime = getDateString(val.orderTime[1]);
			}
			this.Model.searchFromData = objDeepCopy(obj);
		},
		toSearch(val) {
			var params = this.Model.searchFromData;
			this.getList(this,params);
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch: {
		$route: {
			handler(newValue, oldValue) {

			},
			deep: true
		},

	},
	filters: {
		objFilters: function(value) {

		}
	}
}
export default Controller;
